package com.algorithmic.sort;

import java.util.List;

/**
 * @author: zhangxupeng
 * @date:2019/6/25
 * @Email: 1452806452@qq.com
 * 选择排序
 **/
public class SelectSort {
    /**
     * 选择排序
     * 时间复杂度O(N^2)
     * 时间复杂度和冒泡排序相同，但交换次数较少
     * @param list
     */
    public static void selectSort(List<Integer> list) {
        int size = list.size();
        for (int out = 0; out < size - 1; out++) {
            for (int in = out + 1; in < size; in++) {
                if (list.get(in) < list.get(out)) {
                    int tmp = list.get(in);
                    list.set(in, list.get(out));
                    list.set(out, tmp);
                }
            }
        }
    }
}
